@extends('backstage.layout.master')
@section('title', '添加搜索')
@section('style')
@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a href="backstage/searchs/list">筛选列表</a>
            </li>
            <li>
                添加搜索
            </li>
        </ul><!-- .breadcrumb -->
    </div>

    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="page-header">
                    <h1>
                        添加搜索
                    </h1>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <form id="myform" class="form-horizontal" role="form" action="backstage/searchs/add"
                              method="post" enctype="multipart/form-data">
                            <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">

                            <div class="form-group product_form {{$errors->first('search_name')!=""?'has-error':''}}">
                                <label class="col-sm-4 control-label no-padding-right"> 搜索名称 </label>

                                <div class="col-sm-4">
                                    <input type="text" name="search_name" value="{{old('search_name')}}"
                                           id="search_name" placeholder="搜索名称"
                                           class="width-100">
                                </div>
                                <div class="col-sm-4">
                                    <div class="help-block col-xs-12 col-sm-reset inline">{{$errors->first('search_name')}} </div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <input type="hidden" value="{{$search->product_temp_categoty_id}}"
                                   name="product_temp_categoty_id">
                            <input type="hidden" value="{{$search->type}}" name="type">
                            <input type="hidden" value="{{$search->search_id}}" name="pid">
                            <div class="form-group" id="resource-id">
                                <label class="col-sm-4 control-label no-padding-right resource-text"> 群体 </label>

                                <div class="col-sm-4">
                                    <select name="resource_id" id="resource-id-select">

                                    </select>
                                </div>
                                <div class="col-sm-4">
                                    <div class="help-block col-xs-12 col-sm-reset inline">{{$errors->first('resource_id')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="clearfix form-actions">
                                <div class="col-md-offset-5 col-md-7">
                                    <button class="btn btn-info" type="submit">
                                        <i class="icon-ok bigger-110"></i>
                                        保存
                                    </button>

                                    &nbsp; &nbsp; &nbsp;
                                    <button class="btn" type="reset">
                                        <i class="icon-undo bigger-110"></i>
                                        重置
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div><!-- /.col -->
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script src="assets/js/jquery-ui-1.10.3.custom.min.js"></script>
    <script src="assets/js/jquery.slimscroll.min.js"></script>
    <script type="text/javascript">
        var _token = '{{csrf_token()}}';
        var search_arr = '';
        var type = '{{$search->type}}';
        $(function () {
            take_metions(type);
        });
        function take_metions(type) {
            switch (type) {
                case '2':
                    searchCrown();
                    break;
                case '3':
                    searchBrand();
                    break;
                case '4':
                    searchColour();
                    break;
                default:
                    searchStyle();
            }

        }

        function searchCrown() {
            $.ajax({
                type: "POST",
                url: "/backstage/searchs/search-crowd",
                data: {'search': ''},
                success: function (msg) {
                    console.log(msg);
                    if (msg.state == 1) {
                        var html = '';
                        for (var a = 0; a < msg['data'].length; a++) {
                            html += '<option value="' + msg['data'][a].id + '">' + msg['data'][a].crowd_name + '</option><br />';
                        }
                        search_arr = html;
                        $("#resource-id-select").empty();
                        $("#resource-id-select").append(html);
                        $(".resource-text").html('群体');
                    }
                }, error: function () {
                    swal({title: "系统繁忙！", text: "", type: "error", timer: 1000})
                }
            });
        }
        function searchBrand() {
            var brand_keyword = '';
            $.ajax({
                type: "POST",
                url: "/backstage/searchs/search-brand",
                data: {'search': brand_keyword},
                success: function (msg) {
                    if (msg.state == 1) {
                        var html = '';
                        for (var a = 0; a < msg['data'].length; a++) {
                            html += '<option value="' + msg['data'][a].brand_id + '">' + msg['data'][a].brand_name + '</option><br />';
                        }
                        search_arr = html;
                        $("#resource-id-select").empty();
                        $("#resource-id-select").append(html);
                        $(".resource-text").html('品牌');
                    }
                }, error: function () {
                    swal({title: "系统繁忙！", text: "", type: "error", timer: 1000})
                }
            });
        }

        function searchColour() {
            keyword = '';
            $.ajax({
                type: "POST",
                url: "/backstage/searchs/search-colour",
                data: {'search': keyword},
                success: function (msg) {
                    if (msg.state == 1) {
                        var html = '';
                        for (var a = 0; a < msg['data'].length; a++) {
                            html += '<option value="' + msg['data'][a].id + '">' + msg['data'][a].colour_name + '</option><br />';
                        }
                        search_arr = html;
                        $("#resource-id-select").empty();
                        $("#resource-id-select").append(html);
                        $(".resource-text").html('颜色');
                    }
                }, error: function () {
                    swal({title: "系统繁忙！", text: "", type: "error", timer: 1000})
                }
            });
        }

        function searchStyle() {
            keyword = '';
            $.ajax({
                type: "POST",
                url: "/backstage/searchs/search-style",
                data: {'search': keyword},
                success: function (msg) {
                    console.log(msg);
                    if (msg.state == 1) {
                        var html = '';
                        for (var a = 0; a < msg.result.length; a++) {
                            html += '<option value="' + msg.result[a].attr_name + '">' + msg.result[a].attr_name + '</option><br />';
                        }
                        search_arr = html;
                        $("#resource-id-select").empty();
                        $("#resource-id-select").append(html);
                        $(".resource-text").html('款式');
                    }
                }, error: function () {
                    swal({title: "系统繁忙！", text: "", type: "error", timer: 1000})
                }
            });
        }
    </script>
@stop